<?php
header('Content-type:text/html; charset=utf-8');
// Even though the "http://.../html/" folder does not require authentication,  we will force the user to
// enter login: root and password: root so when data is POSTed to the site "http://.../xml/,
// the browser is already sending the proper authentication !!!!!!!!!!!!!

//$digest = $_SERVER['PHP_AUTH_DIGEST'];
if (( $_SERVER['PHP_AUTH_USER'] != "root") && ($_SERVER['PHP_AUTH_PW'] != "root"))
{
     authenticate();
}

function authenticate()
{
    header('WWW-Authenticate: Basic realm="Basic authentication"');
    header('HTTP/1.1 401 Authorization Required');
    echo "Для доступа к ресурсу требуется ввести правильное имя и пароль\n";
    exit;
}
$method = $_SERVER['REQUEST_METHOD'];
if (($_SERVER['REQUEST_METHOD'] == 'PUT') || ($_SERVER['REQUEST_METHOD'] == 'DELETE') || ($_SERVER['REQUEST_METHOD'] == 'POST'))
{
    //  PUT NOT supported 
    header("HTTP/1.1 401 Unauthorized");
    echo 'Метод '.$method . ' не поддерживается';
    return;
}

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
    <head>
        <meta content="text/html; charset=utf-8"
              http-equiv="content-type">
        <title>Добавление новой платы</title>
        <script src="Javascript/mchp.js" type="text/javascript"></script>
        <script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>

    </head>
    <body style="background-color: #5b5b5b; font-family: Comic Sans MS;">
        <div style="width: 400px; border: 1px solid #999; border-top: 0 ; margin: 20px auto; background-color: white; padding: 20px;
             border-top-left-radius:10px; border-top-right-radius: 10px; border-bottom-left-radius: 10px; border-bottom-right-radius: 10px;">
            
                <img style="width: 152px; height: 42px;" alt="" src="./Javascript/mchp.gif">
                <div style="background: #1C6EA9;padding: 4px; font-weight: bold; color: #fff; margin-bottom: 15px;	height: 16px;
                     border-top-left-radius:3px; border-top-right-radius: 3px; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px;">
                    TCP Russian MASTERS
                </div>
                <p>Имя пользователя: <br>
                    <input size="20" id="newuser" type="text" value="<?php echo $_POST['newuser'] ?>"><br>
                    Пароль: <br>
                    <input size="20" id="newpasswd" type="password" type="text" value="<?php echo $_POST['newpasswd'] ?>"><br>
                    Коллекция: <br>
                    <input size="20" id="collection" type="text" value="<?php echo $_POST['collection'] ?>"><br>
                    Имя платы: <br>
                    <input size="20" id="boardname" type="text"><br>
                    <button name="Add" value="Add" onclick="Add()">Добавить</button><br>
                    
                </p>
            
            
                Имя пользователя <br>
                <input size="20" id="user" type="text" value="<?php echo $_POST['newuser'] ?>"><br>
                <button name="Go" value="Go" onclick="GO()">Войти</button>
                <div id="div1">
                    
                </div>
                <br><a href="<?php  echo './'.$_POST['newuser'];?>"><?php echo $_POST['newuser'] ?></a> 
            <script>
                var URL = "";
                //var URL = "http://54.218.57.68";
                //var URL = "http://54.218.30.227";
                function GO()
                {
                    var link = document.getElementById("user").value;
                    link = "./"+link;
                    window.location = link;
                }
                function Add()
                {
                    //var data ='<record><username>luc</username><passwd>luc</passwd><collection>Base</collection><boardname>Win</boardname></record>';
                    var data ='<record>';
                    var user = document.getElementById("newuser").value;
                    data += '<username>'+user+'</username>';
                    var newpasswd = document.getElementById("newpasswd").value;
                    data += '<passwd>'+newpasswd+'</passwd>';
                    var collection = document.getElementById("collection").value;
                    data += '<collection>'+collection+'</collection>';
                    var boardname = document.getElementById("boardname").value;
                    data += '<boardname>'+boardname+'</boardname>';
                    data +='</record>';
                     
                    document.getElementById("div1").innerHTML = "";
                    //link = "./"+link;
                    
                    newAJAXCommand(URL +"/xml/", "POST", Response, 0 , data);
                }
                function Response(xmlData)
                {
                    var rep = xmlData;
                    var result = getXMLValue(xmlData, 'response');
                    //alert(val);
                    document.getElementById("div1").innerHTML = result;
                    document.getElementById("collection").value = "";
                    document.getElementById("boardname").value = "";
                }
            </script>
            <div style="font-size: 0.6em;color: #666;text-align: center;margin: 10px 50px 0 50px;padding-top: 10px;border-top: 1px dotted #666;"id="footer">Copyright &copy; 2013 Microchip Technology,Inc.</div>

        </div>
    </body>
</html>